package cheme.ProcessModel.Cmds;

import org.eclipse.gef.commands.Command;

import cheme.ProcessModel.ModelEnv;
import cheme.ProcessModel.ProcessModelConstants;
import cheme.ProcessModel.ProcessUnits.ProcessUnit;
import cheme.ProcessModel.ProcessUnits.Streams.Stream;


public class CreateStreamCmd extends Command
{
	protected ProcessUnit source = null;
	protected ProcessUnit sink = null;
	
	protected Stream stream = null;

	public CreateStreamCmd(ProcessUnit source)
	{
		this.source = source;
	}
	
	public CreateStreamCmd(CreateStreamCmd src)
	{
		source = src.source;
		sink = src.sink;
		stream = src.stream;
	}
	
	public void execute()
	{
		stream = //new Stream(source);
			(Stream)ModelEnv.getInstanceFor(source).createModelElement(ProcessModelConstants.STREAM, source);
		
		stream.setSource(source);
		stream.setSink(sink);
		
		stream.attachSource();
		stream.attachSink();
	}

	public void setStream(Stream stream)
	{
		this.stream = stream;
	}
	
	public Stream getStream()
	{
		return stream;
	}

	public void setSource(ProcessUnit source)
	{
		assert null != stream;

		this.source = source;
	}
	
	public ProcessUnit getSource()
	{
		return source;
	}

	public void setSink(ProcessUnit sink)
	{
		assert null != stream;

		this.sink = sink;
	}
	
	public ProcessUnit getTarget()
	{
		return sink;
	}

	public void undo()
	{
		assert null != stream;

		stream.detachSource();
		stream.detachSink();
	}
}
